package com.reger.gateway.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.filters.Route;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
import org.springframework.cloud.netflix.zuul.web.ZuulHandlerMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.reger.gateway.service.ZuulRefreshService;

@RestController
@RequestMapping("/route")
public class ZuulRefreshController {

	@Autowired
	private ZuulRefreshService zuulRefreshService;
	@Autowired
	private ZuulHandlerMapping zuulHandlerMapping;

	@GetMapping("/refresh")
	public Map<String, ZuulRoute> refresh() {
		Map<String, ZuulRoute> routes = zuulRefreshService.refreshRoute();
		return routes;
	}

	@GetMapping("/watch")
	public List<Route> watchRoute() {
		List<Route> routes = zuulRefreshService.watchRoute();
		return routes;
	}

	@GetMapping("/watchHandler")
	public String watchRouteHandler() {
		Map<String, Object> handlerMap = zuulHandlerMapping.getHandlerMap();
		return String.valueOf(handlerMap);
	}
}
